<template>
  <el-dialog
    v-el-drag-dialog
    title="驳回申请"
    :visible.sync="visible"
    width="700px"
    @closed="reset"
  >
    <el-form ref="dataForm" class="form" :model="temp" label-position="right" label-width="80px">
      <el-form-item label="退单理由" prop="remark">
        <el-input v-model="temp.remark" type="textarea" :rows="3" maxlength="255" show-word-limit disabled />
      </el-form-item>
      <el-form-item label="驳回理由" prop="refuseReason">
        <el-input v-model="temp.refuseReason" type="textarea" :rows="3" maxlength="255" show-word-limit />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="visible = false">
        关闭
      </el-button>
      <el-button :loading="$loadingPlugin.submit" type="primary" @click="success">
        确认
      </el-button>
    </div>
  </el-dialog>
</template>

<script>
  import { queryRejectRefund } from '@/api'

  export default {
    name: 'reject',
    data() {
      return {
        visible: false,
        temp: {
          remark: '',
          refuseReason: ''
        }
      }
    },
    methods: {
      async open(temp, payTypeMap) {
        this.payTypeMap = payTypeMap
        return new Promise(resolve => {
          this.resolve = resolve
          this.visible = true
          if (temp) {
            this.temp = Object.assign(this.temp, temp)
          }
        })
      },
      success() {
        this.$refs.dataForm.validate(async valid => {
          if (!valid) return
          const params = {
            refundBillCode: this.temp.refundBillCode,
            refuseReason: this.temp.refuseReason
          }
          this.submit(params)
        })
      },
      async submit(params) {
        await queryRejectRefund(params)
        this.resolve()
        this.visible = false
        this.$notify({
          title: '提示',
          message: '驳回成功',
          type: 'success',
          duration: 2000
        })
      },
      reset() {
        this.temp = {
          remark: '',
          refuseReason: ''
        }
        this.$nextTick(() => {
          this.$refs.dataForm.clearValidate()
        })
      }
    }
  }
</script>

<style lang="scss" scoped>

</style>
